import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: JSON.parse(localStorage.getItem('adminInfo') || '{}'),
    token: localStorage.getItem('token') || ''
  }),
  
  actions: {
    updateUser(userInfo) {
      this.userInfo = userInfo
      localStorage.setItem('adminInfo', JSON.stringify(userInfo))
      console.log('Store已更新用户信息:', userInfo)
    },
    
    setToken(token) {
      this.token = token
      localStorage.setItem('token', token)
      console.log('Store已更新token')
    },
    
    logout() {
      this.userInfo = {}
      this.token = ''
      localStorage.removeItem('adminInfo')
      localStorage.removeItem('token')
      console.log('Store已清空用户信息')
    }
  }
}) 